package com.huamoxi.controller;

import cn.hutool.core.util.StrUtil;
import com.huamoxi.annotation.LogRequest;
import com.huamoxi.annotation.RepeatSubmitRequest;
import com.huamoxi.consts.ResponseConst;
import com.huamoxi.entity.User;
import com.huamoxi.result.Result;
import com.huamoxi.service.UserService;
import com.huamoxi.utils.ResultUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@LogRequest
@RequestMapping("/auth")
public class UserController {

    @Resource
    private UserService userService;

    @RepeatSubmitRequest
    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpServletRequest request) {
        if (StrUtil.isBlank(user.getAccount()) || StrUtil.isBlank(user.getPassword()) || user.getSystemId() == null) {
            return ResultUtil.fail(ResponseConst.ERR_PARAMETER);
        }
        return userService.login(user, request);
    }
}
